package main

import (
	"fmt"
	"os"
	"strconv"

	"./even"
	"./prime"
)

type ints struct { a,b int }

func split(n int, source []int) <-chan ints {
	out := make(chan ints)

	go func(){
		for _, a := range source {
			if a > n { break }
			for _, b := range source {
				if b > n { break }
				if b < a { continue }
				if a + b == n {
					out <- ints{a,b}
				}
			}
		}
		close(out)
	}()

	return out
}

func getPrimes(max int) []int {
	primes:=make([]int, 0, max)
	chPrimes:=prime.Generate(max)
	for v := range chPrimes {
		primes = append(primes, v)
	}
	return primes
}

func main() {
	max := 100
	if len(os.Args) > 1 {
		_max, err := strconv.Atoi(os.Args[1])
		if err == nil { max = _max }
	}

	primes := getPrimes(max)

	for v := range even.Generate(4,max) {
		fmt.Print(v)
		for ans := range split(v, primes) {
			fmt.Print(" = (", ans.a, " + ", ans.b , ")")
		}
		fmt.Println()
	}
}
